/*
 * @Description: 子命令的使用
 * @Author: franktrue 807615827@qq.com
 * @Date: 2021-07-27 08:20:55
 * @LastEditTime: 2021-07-27 08:36:47
 */
package main

import (
	"flag"
	"log"
	"strings"
)

var name string

func main() {
	flag.Parse()
	for flag.NArg() <= 0 {
		log.Println("缺少命令行参数")
		return
	}
	args := flag.Args()

	switch strings.ToLower(args[0]) {
	case "go":
		goCmd := flag.NewFlagSet("go", flag.ExitOnError)
		goCmd.StringVar(&name, "name", "Go语言", "帮助信息")
		_ = goCmd.Parse(args[1:])
	case "php":
		phpCmd := flag.NewFlagSet("php", flag.ExitOnError)
		phpCmd.StringVar(&name, "n", "PHP语言", "帮助信息")
		_ = phpCmd.Parse(args[1:])
	default:
		log.Println("当前命令不可用")
		return
	}
	log.Printf("name: %s", name)
}
